<div class="d-flex justify-content-center">
  <div class="col-8">
    <form name="editForm" novalidate (ngSubmit)="save()" [formGroup]="editForm">
      <h2 id="jhi-blog-heading" data-cy="BlogCreateUpdateHeading" jhiTranslate="blogApp.blog.home.createOrEditLabel">
        Create or edit a Blog
      </h2>

      <div>
        <jhi-alert-error></jhi-alert-error>

        @if (editForm.controls.id.value !== null) {
          <div class="mb-3">
            <label class="form-label" for="field_id" jhiTranslate="blogApp.blog.id">ID</label>
            <input type="number" class="form-control" name="id" id="field_id" data-cy="id" formControlName="id" [readonly]="true" />
          </div>
        }

        <div class="mb-3">
          <label class="form-label" for="field_name" jhiTranslate="blogApp.blog.name">Name</label>
          <input type="text" class="form-control" name="name" id="field_name" data-cy="name" formControlName="name" />
          @if (editForm.get('name')!.invalid && (editForm.get('name')!.dirty || editForm.get('name')!.touched)) {
            <div>
              @if (editForm.get('name')?.errors?.required) {
                <small class="form-text text-danger" jhiTranslate="entity.validation.required">This field is required.</small>
              }
              @if (editForm.get('name')?.errors?.minlength) {
                <small class="form-text text-danger" jhiTranslate="entity.validation.minlength" [translateValues]="{ min: '3' }"
                  >This field is required to be at least 3 characters.</small
                >
              }
            </div>
          }
        </div>

        <div class="mb-3">
          <label class="form-label" for="field_handle" jhiTranslate="blogApp.blog.handle">Handle</label>
          <input type="text" class="form-control" name="handle" id="field_handle" data-cy="handle" formControlName="handle" />
          @if (editForm.get('handle')!.invalid && (editForm.get('handle')!.dirty || editForm.get('handle')!.touched)) {
            <div>
              @if (editForm.get('handle')?.errors?.required) {
                <small class="form-text text-danger" jhiTranslate="entity.validation.required">This field is required.</small>
              }
              @if (editForm.get('handle')?.errors?.minlength) {
                <small class="form-text text-danger" jhiTranslate="entity.validation.minlength" [translateValues]="{ min: '2' }"
                  >This field is required to be at least 2 characters.</small
                >
              }
            </div>
          }
        </div>

        <div class="mb-3">
          <label class="form-label" for="field_user" jhiTranslate="blogApp.blog.user">User</label>
          <select class="form-control" id="field_user" data-cy="user" name="user" formControlName="user" [compareWith]="compareUser">
            <option [ngValue]="null"></option>
            @for (userOption of usersSharedCollection; track $index) {
              <option [ngValue]="userOption">{{ userOption.login }}</option>
            }
          </select>
        </div>
      </div>

      <div>
        <button type="button" id="cancel-save" data-cy="entityCreateCancelButton" class="btn btn-secondary" (click)="previousState()">
          <fa-icon icon="ban"></fa-icon>&nbsp;<span jhiTranslate="entity.action.cancel">Cancel</span>
        </button>

        <button
          type="submit"
          id="save-entity"
          data-cy="entityCreateSaveButton"
          [disabled]="editForm.invalid || isSaving"
          class="btn btn-primary"
        >
          <fa-icon icon="save"></fa-icon>&nbsp;<span jhiTranslate="entity.action.save">Save</span>
        </button>
      </div>
    </form>
  </div>
</div>
